<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit :isheader="isheader">
                <div slot="toolheader" border="false" foldbtn='false'>
                    <rx-list-title :title="i18n('list.applyManage','加入机构申请列表')"></rx-list-title>
                  <span class="search-btn-box" v-if="!isheader">
                    <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
                  </span>
                </div>
                <div btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="closeSearchbar">
                    <a-form :layout="colLayout">
                        <a-row :gutter="24">
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('form.applicant','申请人')">
                                    <a-input :placeholder="i18n('form.applicant','申请人','input')" v-model="queryParam.Q_FULLNAME__S_LK"/>
                                </a-form-item>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :bordered="isBorder"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-user/user/org/osInst/applyInstData"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10','30','40']"
                    id-field="pkId"
                    @selectChange="onSelectChange"
                >
                  <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                    <span v-if="record.applyStatus=='APPLY' " @click.stop="agree(record)">{{i18n('list.agree','同意')}}</span>
                    <span v-if="record.applyStatus=='APPLY'" @click.stop="refuse(record)">{{i18n('list.refuse','拒绝')}}</span>
                    <span v-if="record.applyStatus=='ENABLED'" @click.stop="updateUser(record,'DISABLED')">{{i18n('list.disable','禁用用户')}}</span>
                    <span v-if="record.applyStatus=='DISABLED'" @click.stop="updateUser(record,'ENABLED')">{{i18n('list.enable','启用用户')}}</span>
                    <span v-if="record.applyStatus=='REFUSE'"  @click.stop="agree(record)">{{i18n('list.reapprove','重新同意')}}</span>
                  </span>
                </rx-grid>

            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import OsInstApi from '@/api/user/org/osInst'
import {BaseList, RxLayout, RxGrid, RxFit, Util} from "@lowcode/jpaas-common-lib"
import OsInstApplyInstEdit from "./OsInstApplyInstEdit";

export default {
    name: 'OsInstShowApplyInstList',
    components: {
        RxLayout,
        RxGrid,
        RxFit
    },
    mixins: [BaseList],
    data() {
        return {
            // 表头
            columns: [
                {
                    title: this.i18n('form.applicant','申请人'),
                    dataIndex: 'usFullName',
                    width: 120
                },
                {
                    title: this.$ti18('rxForm.notes','备注'),
                    dataIndex: 'applyNote',
                    width: 120
                },
                {
                    title: this.$ti18('rxForm.createTime','创建时间'),
                    dataIndex: 'createTime',
                    width: 160,
                },
                {
                    title: this.$ti18('rxList.action','操作'),
                    width: 60,
                    dataIndex: 'action',
                    scopedSlots: {customRender: 'action'}
                },
            ]
        }
    },
    methods: {
        i18n(name, text, key) {
            return this.$ti18(name, text, "OsInstShowCanApply", key);
        },
        //一开始调用数据
        getListByParams(parameter) {
            return OsInstApi.query(parameter)
        },
        search() {
            this.$refs.table.loadData();
        },
        cancel() {
            this.resetSearch();
        },
        closeSearchbar() {
            //关闭过滤弹窗；（点击X触发）
            this.fitSearch = false;
        },
        agree(record) {
            this.userDialog(record, "1");
        },
        refuse(record) {
            this.userDialog(record, "0");
        },
        updateUser(record,status){
            var self=this;
            var tips=""
            if (status=="DISABLED"){
                tips=this.i18n("msa.disableUser","是否禁用用户？")
            }else if(status=="ENABLED"){
                tips=this.i18n("msa.enableUser","是否启用用户？")
            }
            this.$confirm({
                title: this.$ti18('rxMsa.actionTips','操作提示'),
                zIndex:20000,
                okText: this.$ti18('rxForm.ackBtn','确认'),
                cancelText: this.$ti18('rxForm.cancelBtn','取消'),
                content: tips,
                onOk() {
                    OsInstApi.updateUserStatus(record.tenantId,record.userId,status).then(res=>{
                        self.refreshGrid();
                    })
                },
                onCancel() {
                }
            })
        },
        userDialog(record, approvalType) {
            var self = this;
            var conf = {
                curVm: this,
                widthHeight: ['800px', '600px'],
                shade:true,
                data: {instId: record.id, approvalType: approvalType, tenantId: record.tenantId},
                component: OsInstApplyInstEdit,
                title: this.i18n('prop.applyJoin','处理申请加入本机构人员')
            };
            Util.open(conf, function (action) {
                self.refreshGrid();
            });
        }
    }
}
</script>
